Fix deprecated APIs and correct Python version requirement#94
Conversation
…package can be installed on Python 3.9+ and improve code quality by replacing deprecated codecs.open with built-in open(), using context managers for proper file resource management, updating exception handling from IOError to OSError/FileNotFoundError for Python 3.9+ compatibility, and improving type hints by replacing StreamReaderWriter with TextIOBase from the io module.
pyproject.toml
Outdated
| description = "EditorConfig File Locator and Interpreter for Python" | ||
| readme = "README.rst" | ||
| requires-python = ">=3.13.7" | ||
| requires-python = ">=3.9" |
There was a problem hiding this comment.
3.10 maybe? 3.9 has reached end of line.
There was a problem hiding this comment.
Or, you can keep it this way, and I'll make another PR to correct the classifier altogether.
There was a problem hiding this comment.
Done. I've adjusted the Python version to 3.10 and removed the redundant FileNotFoundError. Thanks for the review.
xuhdev
left a comment
There was a problem hiding this comment.
Thanks for your contribution! I've posted two questions, otherwise the PR looks good.
editorconfig/ini.py
Outdated
| except IOError: | ||
| with open(filename, encoding='utf-8', mode='r') as fp: | ||
| self._read(fp, filename) | ||
| except (OSError, FileNotFoundError): |
There was a problem hiding this comment.
OSError should have covered FileNotFoundError: https://docs.python.org/3/library/exceptions.html#OSError
This exception is raised when a system function returns a system-related error, including I/O failures such as “file not found” or “disk full” (not for illegal argument types or other incidental errors).
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical installation issue caused by an unrealistic Python version requirement (>=3.13.7) and modernizes the codebase by replacing deprecated APIs. The Python version requirement is corrected to >=3.9, aligning with the package classifiers.
Key changes:
- Updated Python version requirement from >=3.13.7 to >=3.9 in pyproject.toml
- Replaced deprecated
codecs.open()with built-inopen()function - Implemented proper resource management using context managers
- Updated exception handling from
IOErrortoOSError/FileNotFoundError - Improved type hints by replacing
StreamReaderWriterwithTextIOBase
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pyproject.toml | Corrects Python version requirement to >=3.9, matching existing classifiers |
| editorconfig/ini.py | Modernizes file handling with context managers, updates deprecated imports and exception types, improves type hints |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
editorconfig/ini.py
Outdated
| except IOError: | ||
| with open(filename, encoding='utf-8', mode='r') as fp: | ||
| self._read(fp, filename) | ||
| except (OSError, FileNotFoundError): |
There was a problem hiding this comment.
FileNotFoundError is a subclass of OSError since Python 3.3. Since this code requires Python 3.9+, catching OSError alone is sufficient and more idiomatic. The explicit FileNotFoundError in the exception tuple is redundant.
| except (OSError, FileNotFoundError): | |
| except OSError: |
This PR fixes a critical issue where the package couldn't be installed due to an invalid Python version requirement (>=3.13.7) and modernizes the codebase by replacing deprecated APIs. The changes include updating the Python version requirement to >=3.9 to match the classifiers, replacing deprecated codecs.open with the built-in open() function, using context managers for proper file resource management, updating exception handling from IOError to OSError/FileNotFoundError for Python 3.9+ compatibility, and improving type hints by replacing StreamReaderWriter with TextIOBase. All changes are backward compatible and have been thoroughly tested.